package thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class demo32 {
    public static void main(String[] args) throws InterruptedException {
        //使用这个对象来记录拆分出来的任务执行的个数---如果全部执行完毕了 那么await方法就会放行
        CountDownLatch cdl=new CountDownLatch(10);

        //弄一个线程池来执行所有的子任务
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        for(int i = 0; i < 10; i++) {
            executorService.submit(new Runnable() {
                @Override
                 public void run() {
                     System.out.println("正在执行子任务" + "i");
                    System.out.println("子任务" + "i" + "执行完毕");
                     cdl.countDown();
                 }

            });
        }
        cdl.await();
        System.out.println("等待结束,main线程执行");
        executorService.shutdown();
    }
}
